import Vue from 'vue'
import Vuex from 'vuex'
import { getToken, setToken } from "@/utils/storage";

Vue.use(Vuex)

const TOKEN_KEY = 'TOUTIAO_TOKEN'
export default new Vuex.Store({
  state: {
    // token: JSON.parse(window.localStorage.getItem(TOKEN_KEY))
    token: getToken(TOKEN_KEY),
    userId: null
  },
  mutations: {
    setUser(state, token) {
      state.token = token
      // window.localStorage.setItem(TOKEN_KEY, JSON.stringify(token))
      setToken(TOKEN_KEY, state.token)
    },
    setUserId(state, id) {
      state.userId = id
    }
  },
  actions: {
  },
  modules: {
  }
})
